﻿// ===============================================================================
// XCI.WinForm.Platform 西安交通信息WinForm开发框架 2019 版权所有
// ===============================================================================

using System;
using XCI.Extensions;
using XCI.Helper;
using XCI.Sys.Filter;
using XCI.Sys.Model;
using XCI.Sys.Service;

namespace XCI.Windows
{
    [System.ComponentModel.DesignerCategory("Code")]
    public class EnterprisePopupGridEdit : PopupGridControlPagingEdit
    {
        public override string ValueMember => "Id";
        public override string DisplayMember => "Name";
        public override Type ModelType => typeof(SysRole);
        public override string Id => "popup-grid-0420fdeb8eb74a2cbdede9a0043f11c5";

        protected override void OnLoadList(PopupGridControlPagingLoadListEventArgs e)
        {
            if (WinFormHelper.IsDesignMode()) return;
            var filter = new SysRoleFilter();
            filter.CombinePageFilter(e.PageFilter);
            filter.Key = e.Key;
            e.Task = async () => await SysRoleService.Instance.SelectPageListAsync(filter);
        }

        protected override void OnLoadSingle(PopupGridControlPagingLoadSingleEventArgs e)
        {
            if (WinFormHelper.IsDesignMode()) return;
            if (e.BindValue.IsEmpty()) return;
            e.Task = async () => await SysRoleService.Instance.SelectByIdAsync(e.BindValue.ToStringOrEmpty());
        }
    }
}